package com.arsn.myf.system.controller;

import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.arsn.myf.system.entity.ApiLog;
import com.arsn.myf.system.service.ApiLogService;
import com.arsn.myf.system.vo.ApiLogVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;
import java.util.Arrays;

/**
 * 接口操作日志
 * @author zhongrj
 * @since 2022-08-11
 */
@RestController
@RequestMapping("/apiLog")
@AllArgsConstructor
@Api(value = "接口操作日志", tags = "接口操作日志")
public class ApiLogController {

    private final ApiLogService apiLogService;


    /**
     * 查询接口操作日志的分页数据
     * @param page
     * @param apiLog
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询接口操作日志的分页数据")
    public R list(Page<ApiLog> page, ApiLog apiLog){
        return R.data(apiLogService.page(page,new QueryWrapper<>(apiLog)));
    }


    /**
     * 自定义接口操作日志的分页数据
     * @param page
     * @param apiLog
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "自定义接口操作日志的分页数据")
    public R page(Page<ApiLogVO> page, ApiLogVO apiLog){
        return R.data(apiLogService.selectPageApiLogList(page,apiLog));
    }


    /**
     * 接口操作日志详情信息
     * @param apiLog
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "接口操作日志详情信息")
    public R detail(ApiLog apiLog){
        return R.data(apiLogService.getOne(new QueryWrapper<>(apiLog)));
    }


    /**
     * 接口操作日志新增
     * @param apiLog
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "接口操作日志新增")
    public R save(@RequestBody ApiLog apiLog){
        return R.status(apiLogService.save(apiLog));
    }

    /**
     * 接口操作日志修改
     * @param apiLog
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "接口操作日志修改")
    public R update(@RequestBody ApiLog apiLog){
        return R.status(apiLogService.updateById(apiLog));
    }


    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(apiLogService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }
}
